package org.ly.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.ly.dq.bean.WeiXiu;
import org.ly.dq.bean.WeiXiuDate;
import org.nutz.dao.Dao;

public class WeiXiuDateUtil {

	/**
	 * 传入一个时间和当前时间比对是否超过标准
	 * 
	 * @return 0 超过 1 正常
	 */

	public static String getWeiXiuDateFlag(Date date) {

		try {
			Date newDate = new Date();
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
			String dString = df.format(newDate);
			newDate = df.parse(dString);
			Long newdateTime = newDate.getTime();
			Long bxDateTime = date.getTime();
			Long dateB = (long) (1000 * 60 * 60 *24 *3);
			if (newdateTime - bxDateTime > dateB) {
				return "0";
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return "1";
	}
	
	
	/**
	 * 将weixiu 集合转换成  WeiXiuDate集合
	 * @param lists 维修集合
	 * @return WeiXiuDate 集合
	 */
	public static List<WeiXiuDate> getWeiXiuDates(List<WeiXiu> lists, Dao dao){
		List<WeiXiuDate> newList = new ArrayList<WeiXiuDate>();
		for (WeiXiu weiXiu : lists) {
			weiXiu = dao.fetchLinks(weiXiu, "wuLiaos");
			String weiXiuDateFlag = WeiXiuDateUtil.getWeiXiuDateFlag(weiXiu.getBaoXiuRiQi());
			WeiXiuDate weiXiuDate = new WeiXiuDate(weiXiu, weiXiuDateFlag);
			newList.add(weiXiuDate);
		}
		return newList;
	}

}
